﻿Type=StaticCode
Version=2.71
@EndOfDesignText@
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Dim GV_AppPath As String : GV_AppPath = File.DirDefaultExternal  '程序目录
	Dim GV_ConfigDBFileName As String			: GV_ConfigDBFileName = "config.db"  '配置数据库模拟过程
	
	Dim GV_SQLTool As SQL
	Dim GV_JSonTool As JSONParser
	
	Dim GV_ServerIP As String                   '远程服务器IP
	Dim GV_ServerPort As Int                    '远程服务器端口
	Dim GV_ConnTimeOut As Int    : GV_ConnTimeOut = 50000              '连接超时 时间 1000毫秒=1秒
	Dim GV_UserSession As String                'session
	Dim GV_UserCode As String
	
	Dim GV_DesTool As DesClient                '加密工具
	Dim GV_DesKey As String : GV_DesKey = "_fly2ky_"   '加密Key 8位字符
	
	Dim GV_Version As Double :  GV_Version = 0.1                          '版本号
	
	Dim GV_Login As Boolean
	Dim GV_ApkName As String : GV_ApkName = "HisHLXT.apk"                 'Apk文件名
	Dim GV_AppType As String : GV_AppType = "2"                           '2护理系统 
	
	Dim GV_JC_XM As String
	
	Dim GV_SESSION_TIME_OUT_CODE As String : GV_SESSION_TIME_OUT_CODE = "-999999"  '会话超时Code
	
	Dim GV_Login_KSBM As String    '登陆科室
	'Dim GV_Login_KSMC As String    '登陆科室
	
	Dim GV_ListView_ItemHeight As Int = 40    'listView高度
	Dim GV_ListView_TextSize As Float = 25    '字体
	Dim GV_ListView_TextSize2 As Float = 16    '字体
	Dim GV_ListView_TextColor As Int = Colors.White
	Dim GV_EditText_Height As Int = 50        '
	
	Dim GV_HostTab_TextSize As Int = 15
	
	Dim GV_HTML_ADD_DATA_BEGIN As String : GV_HTML_ADD_DATA_BEGIN = "##HTML_ADD_DATA_BEGIN##" '附加数据开始
	Dim GV_HTML_ADD_DATA_END As String : GV_HTML_ADD_DATA_END = "##HTML_ADD_DATA_END##"     '附加数据结束


	Dim GV_XTTZ_RefreshTime As Int : GV_XTTZ_RefreshTime = 600          '通知刷新时间 秒 
	Dim GV_TB_RefreshTime As Int : GV_TB_RefreshTime = 600              '同步刷新时间 秒
	
	Dim GV_ImagePath As String  
	
End Sub

Sub InitData
	If File.Exists(File.DirDefaultExternal, GV_ConfigDBFileName) = False Then
		GV_AppPath = CopyDBFromAssets(GV_ConfigDBFileName)
	End If

	GV_SQLTool.Initialize(GV_AppPath, GV_ConfigDBFileName, True)

	If File.Exists(GV_AppPath,"/Image") = False Then
		File.MakeDir(GV_AppPath,"/Image")
	End If
	
	If File.Exists(GV_AppPath,"/Cache") = False Then
		File.MakeDir(GV_AppPath,"/Cache")
	End If
	
	InitData_ServerConfig
	
	GV_Login_KSBM = ""
	'GV_Login_KSMC = ""
	
	
End Sub

Sub InitData_ServerConfig
	Dim DataSetConfig As Cursor
	Dim sSql As String
	
	sSql = "SELECT SERVERIP,SERVERPORT FROM ZD_CONFIG "
	Log("SQL: " & sSql)
	DataSetConfig = GV_SQLTool.ExecQuery(sSql)
	If DataSetConfig.RowCount > 0 Then
		DataSetConfig.Position = 0
		GV_ServerIP = DataSetConfig.GetString("SERVERIP")
		GV_ServerPort = DataSetConfig.GetInt("SERVERPORT")
	End If
	DataSetConfig.Close
	
End Sub

Sub GetServerUrl As String
	Return "http://"&GV_ServerIP&":"&GV_ServerPort

End Sub

Sub CheckSession(ACode As String)
	If ACode = GV_SESSION_TIME_OUT_CODE Then
		ProgressDialogHide
		Msgbox("已经超时，或者服务器已注销会话连接，需要重新登录","提示")
		StartActivity("Login")
	End If

End Sub

Sub DRQ2BRQ(ARQ As Int) As Long
	Dim lRQ As Long
	lRQ = (ARQ - 25569)
	Return 86400000 * lRQ

End Sub

Sub BRQ2DRQ(ARQ As Long) As Int
	Dim iRQ As Int
	iRQ = ARQ / 86400000
	Return iRQ + 25569

End Sub

Sub CopyDBFromAssets (FileName As String) As String
	Dim TargetDir As String
	If File.ExternalWritable Then TargetDir = File.DirDefaultExternal Else TargetDir = File.DirInternal
	If File.Exists(TargetDir, FileName) = False Then
		File.Copy(File.DirAssets, FileName, TargetDir, FileName)
	End If
	Return TargetDir
End Sub